﻿using System;
using System.IO;

namespace Netbits.Common.Extensions
{
	/// <summary>
	/// Extensions Methods for System.IO.File-Class
	/// </summary>
	public static class FileExtensions
	{
		/// <summary>
		/// Combine Path with Filename. 
		/// Checks if we are under linux or windows.
		/// </summary>
		/// <param name="Path_">Path</param>
		/// <param name="File_">Filename</param>
		/// <returns>Returns the combined path/file.</returns>
		public static string Combine( string Path_, string File_ )
		{
			if( string.IsNullOrEmpty( Path_ ) )
				return File_;

			if( string.IsNullOrEmpty( File_ ) )
				return Path_;

			string path = Path_;
			if( Path_.EndsWith( "/", StringComparison.InvariantCulture ) && Path_.EndsWith( "\\", StringComparison.InvariantCulture ) )
				path += "/";

			path += File_;
			int p = (int)Environment.OSVersion.Platform;
			if( (p == 4) || (p == 6) || (p == 128) )
				return path.Replace( "\\", "/" );

			return path.Replace( "/", "\\" );
		}
	}
}
